package priv.stones.io.Scanner.file;

import java.io.*;

/**
 * @Author: Stones
 * @Description:内存流合并文件
 * @Date: 2017/11/1 11:10
 */
public class MemoryIo2 {

    public static void main(String[] args) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        String[] files = {"e:\\1.txt", "e:\\2.txt"};
        for (int i = 0; i < files.length; i++) {
            InputStream inputStream = new FileInputStream(files[i]);
            int data;
            while ((data = inputStream.read()) != -1) {
                byteArrayOutputStream.write(data);
            }
            inputStream.close();
        }
        OutputStream os = new FileOutputStream("e:\\3.txt");
        os.write(byteArrayOutputStream.toByteArray());
        os.close();
        byteArrayOutputStream.close();
    }

}
